package com.application.outdoor.pojo;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;

import com.application.Network.Protocol;

import android.util.Log;

import ReadWriteXML.XMLBuilder;

public class CayThaoLuanPOJO {
	private int id;
	private long version;
	private String noiDung;
	private int idNhom;
	private String nguoiTao;
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	public long getVersion() {
		return version;
	}
	public void setVersion(long version) {
		this.version = version;
	}
	public String getNoiDung() {
		return noiDung;
	}
	public void setNoiDung(String noiDung) {
		this.noiDung = noiDung;
	}
	public int getIdNhom() {
		return idNhom;
	}
	public void setIdNhom(int idNhom) {
		this.idNhom = idNhom;
	}
	public String getNguoiTao() {
		return nguoiTao;
	}
	public void setNguoiTao(String nguoiTao) {
		this.nguoiTao = nguoiTao;
	}
	
	public Element createXMLElement(Document doc){
		Element e=doc.createElement("Cay");
		e.setAttribute("ID", this.id+"");
		e.setAttribute("version", this.version+"");
		e.setAttribute("NoiDung", this.noiDung);
		e.setAttribute("IDNhom", this.idNhom+"");
		e.setAttribute("NguoiTao", this.nguoiTao+"");
		return e;
	}
	public void getFromXMLElement(Element element){
		this.id = Integer.parseInt(element.getAttribute("ID"));
		this.noiDung = element.getAttribute("NoiDung");
		this.idNhom=Integer.parseInt(element.getAttribute("IDNhom"));
		this.nguoiTao=element.getAttribute("NguoiTao");
		this.version=Long.parseLong(element.getAttribute("version"));
	}
	public void parseFromStringXML(String xml){
		try {
			Document doc = XMLBuilder.loadXMLFromString(xml);
			Element e = (Element) doc.getFirstChild().getFirstChild();
			this.getFromXMLElement(e);
		} catch (Exception e) {
			Log.e(Protocol.TAG, "CayThaoLuanPOJO parseFromStringXML "+e.getMessage());
		}
		
	}
}
